package com.nativetalk.service.three.coupon.search;

import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.coupon.TdNtCouponDetail;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.dao.TdNtCouponDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by lizhun on 16/8/13.
 */
@Service
public class ThreeCouponSearchServiceImpl implements ThreeCouponSearchService {
    private static Logger logger = Logger.getLogger(ThreeCouponSearchServiceImpl.class);
    @Resource
    private TdNtCouponDao tdNtCouponDao;
    @Override
    public RetInfo findCouponByMembId(int memb_id) {
        String logInfo = this.getClass().getName() + ":findCouponByMembId:";
        // 类路径+方法名
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            TdNtCouponDetail tdNtCouponDetail = new TdNtCouponDetail();
            tdNtCouponDetail.setMemb_id(memb_id);
            tdNtCouponDetail.setType(2);
            tdNtCouponDetail.setLimit_id(0);
            tdNtCouponDetail.setTime(1);
            TdNtCouponDetail detail = tdNtCouponDao.findTdNtCouponDetail(tdNtCouponDetail);
            if (detail != null) {
                retInfo.setMark(ValidationMessages.getValue("MARKYES"));
                retInfo.setTip("获取优惠券成功");
                retInfo.setObj(detail.getState());
            } else {
                retInfo.setMark(ValidationMessages.getValue("MARKNO"));
                retInfo.setTip("没有优惠券");
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(),e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
}
